import {ElMessage} from "element-plus";
import {ref, computed} from 'vue'
import {defineStore} from 'pinia'
import {getRecommendAPI} from '../apis/common'


export const useRecommendStore = defineStore('recommend', () => {

    // 一种类型的小说对应一类推荐 
    const recommend = ref({})

    const getRecommend = async (type) => {
      if (recommend.value[type] == undefined ) {
        const res = await getRecommendAPI(type)
        recommend.value[type] = res.data
      }
      return recommend.value[type]
    }

    return {
      recommend,
      getRecommend
    }
  },
  {
    persist: {
      key: "recommend",
      storage: sessionStorage,
      // paths: ["token", "loginUserInfo"],
      serializer: {
        deserialize: JSON.parse,
        serialize: JSON.stringify,
      },
    }
  }
)
